package com.education.wisdom.controller.app;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.education.common.core.BaseController;
import com.education.common.utils.BusinessType;
import com.education.common.utils.LogUtil;
import com.education.wisdom.pojo.Anchorinformation;
import com.education.wisdom.service.IAnchorinformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 主播 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-02-18
 */
@Controller
@CrossOrigin
@Slf4j
@Api(tags = {"主播 信息操作处理"})
@RequestMapping("/appAnchorinformation")
public class AppanchorinformationController extends BaseController
{
    private String prefix = "system/anchorinformation";
	
	@Autowired
	private IAnchorinformationService anchorinformationService;
	
	@GetMapping()
	public String anchorinformation()
	{
	    return prefix + "/anchorinformation";
	}
	
	/**
	 * 新增主播
	 */
	@ApiOperation("新增主播信息")
	@PostMapping("/addAnchor")
	@ResponseBody
	@ApiImplicitParams({
		@ApiImplicitParam(name="userId",value="用户编号",required=true,dataType="String"),
		@ApiImplicitParam(name="livetype",value="直播类型",required=true,dataType="String"),
		@ApiImplicitParam(name="nickname",value="主播昵称",required=true,dataType="String"),
		@ApiImplicitParam(name="sex",value="主播性别",required=true,dataType="String"),
		@ApiImplicitParam(name="summary",value="主播描述",required=true,dataType="String"),
		@ApiImplicitParam(name="telphone",value="手机号码",required=true,dataType="String")
	})
	public void addAnchor(HttpServletResponse response, HttpServletRequest request, Anchorinformation anchorinformation)throws Exception{
			
		log.info(LogUtil.LogInfo("新增主播信息",new Date()));
			anchorinformation.setCreateTime(new Date());
        	writeJSON(anchorinformationService.insertAnchorinformation(anchorinformation), response,  "200", "成功");   
	}
	
	/**
	 * 查询主播信息
	 */
	@ApiOperation("查询主播认证是否通过")
	@GetMapping("/isTure")
	@ResponseBody
	@ApiImplicitParams({
		@ApiImplicitParam(name="userId",value="用户编号",required=true,dataType="String")
	})
	public void isTure(HttpServletResponse response,HttpServletRequest request,String userId)throws Exception{	
			
		log.info(LogUtil.LogInfo("查询主播认证是否通过",new Date()));
			Anchorinformation anchorinformation = anchorinformationService.selectAnchorinformationById(userId);
			if (anchorinformation != null) {
				String isTure = anchorinformation.getIsTure();
				if (isTure.equals("1")) {
					writeJSON("已通过", response,  "200", "成功");
				}else if (isTure.equals("2")){
					writeJSON("认证中", response,  "200", "成功");
				}else if (isTure.equals("3")){
					writeJSON("未通过", response,  "200", "成功");
				}
			}else {
	        	writeJSON("未认证", response,  "200", "成功");   

			}
	
	}
	
	/**
	 * 达人直播首页根据状态查询主播
	 */
	@ApiOperation("达人直播首页根据状态查询主播")
	@GetMapping("/showAnchorList")
	@ResponseBody
	public void showLive(HttpServletResponse response,HttpServletRequest request,String livetype,Integer pageNo)throws Exception{

		Integer pageSize = 20;
		PageHelper.startPage(pageNo.intValue(), pageSize.intValue());
		log.info(LogUtil.LogInfo("达人直播首页根据状态查询主播",new Date()));
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("livetype", livetype);
		List<Anchorinformation> list = anchorinformationService.selectShowLiveByType(map);
		writeJSON(new PageInfo<Anchorinformation>(list), response,  "200", "成功");
	}


	/**
	 * 查询主播是否提交资料
	 */
	@ApiOperation("查询主播是否提交资料")
	@GetMapping("/isTake")
	@ResponseBody
	public void isTake(HttpServletResponse response,HttpServletRequest request,String userId)throws Exception{	
		log.info(LogUtil.LogInfo("查询主播是否提交资料",new Date()));
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("userId", userId);
			Anchorinformation anchorinformation = anchorinformationService.selectIsTake(map);
			if (anchorinformation != null) {
				writeJSON(anchorinformation, response,  "200", "成功");
			}else {
				Map<String, Object> map1 = new HashMap<String, Object>();
				map1.put("isTure", "未提交资料");
				writeJSON(map1, response,  "200", "成功");
			}
        	   
	}
	
}
